package com.koron.common.core.business.log.util.redisImpl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @ClassName RedisPublisher
 * @description
 * @Author zhouj
 * @Date 2021/10/20 16:33
 */
@Slf4j
@Component
public class OperateLogRedisPublisher {

    @Autowired
    StringRedisTemplate redisTemplate;

    public void publish(String channel, Object o) {

        try {
            redisTemplate.convertAndSend(channel, JSON.toJSONString(o));
        } catch (Exception ex) {
            log.error("发布操作日志消息到redis失败 {}", ex.getMessage());
        }
    }

}
